<?php
/**
 * TestGuest Version1.0
 * ================================================
 * Copy 2017-2018 zxj
 * Web: http://www.zhaoxiaojie.club
 * ================================================
 * Author: Zxj
 * Date: 17/8/11
 * Time: 下午4:42
 * 接收版块id请求,读取版块详情数据,并渲染到版块详情模板
 *
 */
session_start();
//设置响应头
header('content-type:text/html;charset=utf-8');
//引入配置文件
include_once 'common/function.inc.php';
include_once 'common/config.inc.php';
include_once 'common/ini.php';

if(!empty($_GET['id'])){

    $id = intval($_GET['id']);

    //连接数据库
    include 'common/mysql.inc.php';

    //根据id获取当前版块数据
    $sql = "select * from bbs_forum WHERE id='$id'";
    $res1 = mysql_query($sql);
    $row = mysql_fetch_assoc($res1);

    //获取上一级版块数据
    $pid = $row['pid'];
    $sql4 = "select * from bbs_forum WHERE id =$pid";
    $res4 = mysql_query($sql4);
    $fuji = mysql_fetch_assoc($res4);

    //获取所有主版块的信息~
    $sql2 = "select * from bbs_forum WHERE pid=0 ORDER BY sort ASC";

    $res2 = mysql_query($sql2);
    while($rows = mysql_fetch_assoc($res2)){

          $zhubankuai[] = $rows;

    }

    //**********根据id获取板块下文章的数据(分页获取)*************/
    //1.获取总数量

    //****添加搜索******/
    $keywords = isset($_GET['keywords'])?$_GET['keywords']:'';

    if($keywords==''){

        $sqlzongshu = "select count(*) as num from bbs_notes where fid=$id";

    }else{

        $sqlzongshu = "select count(*) as num from bbs_notes where fid=$id AND title LIKE '%$keywords%'";

    }

    $data = mysql_fetch_assoc(mysql_query($sqlzongshu));
    $sum = $data['num'];
    //定义每页显示数量$pagesize
    $pagesize = 3;

    //最大页数
    $max = ceil($sum/$pagesize);

    //获取当前页码
    $page = isset($_GET['page'])?$_GET['page']:1;

    //获取上一页,下一页
    $prev = $page-1;
    $next = $page+1;

    //越界处理
    if($prev<1){

        $prev = 1;

    }

    if($next>$max){

        $next = $max;

    }

    //echo $page;

    //偏移量(从哪个数据开始查询的最小为0)
    $start = $pagesize*($page-1);

    if($keywords==''){

        $sql3 = "select * from bbs_notes WHERE fid='$id' ORDER BY addtime DESC limit $start,$pagesize";

    }else{

        $sql3 = "select * from bbs_notes WHERE fid='$id' AND title LIKE '%$keywords%' ORDER BY addtime DESC limit $start,$pagesize";
        //dd($sql3);
    }

    $res3 = mysql_query($sql3);
    while($rows3 = mysql_fetch_assoc($res3)){

        $notes[] = $rows3;

    }
    //dd($notes);
    //**********根据id获取板块下文章的数据(分页获取)*************/

    //封装底下每一页的数组//

    for($i=1;$i<=$max;$i++){

       $yema[$i] = $i;

    }

    //dd($row);

    //var_dump($yema);die();

    //引入视图文件,然后渲染数据
    include VIEW.'/forum.html';

}else{

    _alert_back('参数不正确!');

}


?>